package com.lc.railway.ui.fragment;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.base.BaseDialog;
import com.lc.railway.R;
import com.lc.railway.app.AppFragment;
import com.lc.railway.manager.ActivityManager;
import com.lc.railway.other.IntentKey;
import com.lc.railway.ui.activity.CaptureActivity;
import com.lc.railway.ui.activity.CollectActivity;
import com.lc.railway.ui.activity.HomeActivity;
import com.lc.railway.ui.activity.LoginActivity;
import com.lc.railway.ui.activity.PowerActivity;
import com.lc.railway.ui.dialog.MessageDialog;
import com.lc.railway.util.SPUtil;
import com.lc.widget.layout.SettingBar;

import androidx.appcompat.widget.AppCompatImageView;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : Android 轮子哥
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/10/18
 * desc   : 我的 Fragment
 */
public final class MeFragment extends AppFragment<HomeActivity> {


    @BindView(R.id.iv_header_icon)
    AppCompatImageView ivHeaderIcon;
    @BindView(R.id.name_tv)
    TextView nameTv;
    @BindView(R.id.tv_company)
    TextView tvCompany;
    @BindView(R.id.rl_top)
    RelativeLayout rlTop;
    @BindView(R.id.sb_power)
    SettingBar sbPower;
    @BindView(R.id.sb_out)
    SettingBar sbOut;
    @BindView(R.id.sb_shoucng)
    SettingBar sbShoucng;
    @BindView(R.id.sb_jilu)
    SettingBar sbJilu;

    @Override
    protected int getLayoutId() {
        return R.layout.me_fragment;
    }

    @Override
    protected void initView() {

    }

    @Override
    public void onStart() {
        super.onStart();
        nameTv.setText("警号" + SPUtil.get(getContext(), IntentKey.PHONE, ""));
        tvCompany.setText(SPUtil.get(getContext(), IntentKey.NAME, ""));
    }

    @Override
    protected void initData() {

    }


    @OnClick({R.id.sb_power, R.id.sb_out,R.id.sb_shoucng, R.id.sb_jilu})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sb_power:
                startActivity(PowerActivity.class);
                break;
            case R.id.sb_out:
                // 消息对话框
                new MessageDialog.Builder(getActivity())
                        // 标题可以不用填写
                        .setTitle("退出登录")
                        // 内容必须要填写
                        .setMessage("您是否要退出登录？")
                        // 确定按钮文本
                        .setConfirm(getString(R.string.common_confirm))
                        // 设置 null 表示不显示取消按钮
                        .setCancel(getString(R.string.common_cancel))
                        // 设置点击按钮后不关闭对话框
                        //.setAutoDismiss(false)
                        .setListener(new MessageDialog.OnListener() {

                            @Override
                            public void onConfirm(BaseDialog dialog) {
                                // 进行内存优化，销毁除登录页之外的所有界面
                                ActivityManager.getInstance().finishAllActivities(HomeActivity.class);
                                startActivity(LoginActivity.class);

                                SPUtil.remove(getContext(), IntentKey.ID);

                            }

                            @Override
                            public void onCancel(BaseDialog dialog) {
                                dialog.dismiss();
                            }
                        })
                        .show();
                break;
            case R.id.sb_shoucng:
                startActivity(CollectActivity.class);
                break;
            case R.id.sb_jilu:
                startActivity(CaptureActivity.class);

                break;
        }
    }


}